Using Postman to test Assetic API's
Introduction
Postman is very convenient when it comes to executing API's. With Postman, users are allowed to create and save simple and complex HTTP/s requests, as well as read their responses. Users can use them repeatedly, without having to remember the exact endpoint, headers, API keys, etc.
Being an Open Source tool, Postman can be easily download from https://www.postman.com/downloads/ or can be instantly accessed from https://www.postman.com/ without having to install a desktop app.
Postman Collection for Assetic REST API
To get started with Postman and Assetic API's a Postman 'Collection' is available to download and use to test the Assetic APIs.
The collection includes examples for Assetic REST API's and Assetic OData endpoints.
The collection is provided 'as-is' for testing purposes and should be validated in your Assetic Sandbox prior to using in Production to ensure the desired outcomes are achieved.
You may need to right click and ‘Save As’ to download the .json file
Importing the Assetic Postman Collection
The downloaded json file can be imported into Postman and will create a collection titled 'Assetic Cloud Test Suite'
- Launch Postman either from desktop app or web version
- Click Import
- Choose the downloaded assetic_rest_api.json file
Fill the details and remember to click ‘Save’Assetic site: your Assetic environment i.e. (https://your_org.assetic.net)
Assetic user: Username
Assetic Token: Your API Key.
To retrieve an API Key refer to the Assetic Knowledge Base article REST-API-Introduction
- Once saved, go to ‘Validate Login’ request and click send. If you get status “200”, then you are validated.
Using the Collection
As shown in step 5. above, the 'Send' button is used to run the currently selected request.
Parameters and Variables
Some API's require parameters or Json payloads.
When a request is run, it may save some properties of the request response as variables. These variables are then used as inputs into other requests within the 'Assetic Cloud Test Suite' Postman collection.
Variables are represented in Postman request parameters and the Body json as the name of the variable enclosed by 2 curly parenthesis i.e. {{asset_id}} is the variable holding the current value of Asset Id.
If you click on the 'Tests' tab of a request you may see some javascript. This javascript is setting environment variables.
Example via Asset Create and Update requests
In the screenshot below for the "Create Assets- Minimal payload for creating Asset" request the 'Tests' will create/update environment variables that record:
- "Asset Id" (asset_id)
- Asset unique internal Id (asset_guid)
- Last Modified Date (LastModifed)
In the screenshot below for the "Update asset details" request the request Body uses the environment variable variables set above for "AssetId", "LastModified"